Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

fix(server): handle kernel signals by including tini #1388

Closed
wants to merge 2 commits into from

Conversation

PixnBits
Copy link
Contributor

Description

Wrap the Node.js process with the tini init wrapper. This enables proper kernel signal handling inside the container, removing the need for forceful shutdowns (e.g. $ docker ps; docker kill <container-id>).

This adds 96kB to the image size.

We may later be able to remove src/server/shutdown.js if the Babel issue is resolved (it's been a number of years). Though, it might serve has a failure handling in the event we miss something that keeps Node.js running (e.g. a setInterval without .unref()).

Motivation and Context

Node.js was not designed to run as PID 1 which leads to unexpected behaviour when running inside of Docker. For example, a Node.js process running as PID 1 will not respond to SIGINT (CTRL-C) and similar signals. ...
You can...include Tini directly in your Dockerfile, ensuring your process is always started with an init wrapper.

https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#handling-kernel-signals

How Has This Been Tested?

I've built the image locally, used it via @americanexpress/one-app-runner (npm start -- --offline --docker-image=sha256:...) and upon CTRL+C the container stops (due to the Node.js process ending).

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (adding or updating documentation)
  • Dependency update
  • Security update

Checklist:

  • My change requires a change to the documentation and I have updated the documentation accordingly.
  • These changes should be applied to a maintenance branch. (this is that PR, see fix(server): handle kernel signals by including tini #1387)
  • This change requires cross browser checks.
  • Performance tests should be ran against the server prior to merging.
  • This change impacts caching for client browsers.
  • This change impacts HTTP headers.
  • This change adds additional environment variable requirements for One App users.
  • I have added the Apache 2.0 license header to any new files created.

What is the Impact to Developers Using One App?

Don't have to wait 10,000ms for the shutdown check to run. Should also be more graceful and faster shutdowns in production.

Copy link
Contributor

github-actions bot commented Apr 13, 2024

Size Change: 0 B

Total Size: 694 kB

ℹ️ View Unchanged
Filename Size
./build/app/app.js 159 kB
./build/app/app~vendors.js 401 kB
./build/app/runtime.js 7.07 kB
./build/app/service-worker-client.js 7.25 kB
./build/app/vendors.js 120 kB

compressed-size-action

@10xLaCroixDrinker
Copy link
Member

This approach could resolve the issue with #1387

@PixnBits PixnBits marked this pull request as ready for review April 16, 2024 17:49
@PixnBits PixnBits requested review from a team as code owners April 16, 2024 17:49
@PixnBits PixnBits requested a review from a team April 18, 2024 18:40
@10xLaCroixDrinker 10xLaCroixDrinker deleted the fix/handle-kernel-signals_5.x.x branch May 3, 2024 20:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants